<template>
  <div>
    <div>
      <el-button size="mini" @click="dialogVisible = true" type="primary">Leave a Message</el-button>
    </div>
    <ul>
      <li class="li back-fff" v-for="(item, index) in MessageList" :key="index" @click.stop="toItem(item)">
        <div class="h4">{{ item.F_CommentTitle }}</div>
        <div class="icons flex-between">
          <div class="flex">
            <div class="item">{{ item.answerCount }}</div>
            <div class="item">{{$ut.dateFormat(item.F_CommentDate)}}</div>
          </div>
          <div class="deletes" @click.stop="deletes(item)">Delete</div>
        </div>
      </li>
    </ul>
    <BaseNull v-if="BaseNull" />
    <div class="back-fff pages flex-end">
      <el-pagination :page-size="pageSizs" layout="total, sizes , prev, pager, next , jumper" :total="totalCount" :current-page="pageNum" @current-change="onPageChange" @size-change="onSizeChange">
      </el-pagination>
    </div>
    <el-dialog title="Create Issue" :visible.sync="dialogVisible" width="650px">
      <el-input v-model="form.F_CommentTitle" placeholder="标题"></el-input>
      <el-input class="mt-15" type="textarea" :rows="2" placeholder="请输入内容" v-model="form.F_Comment">
      </el-input>
      <el-button class="mt-15" type="primary" size="medium" @click="CreateMessage">Submit</el-button>
    </el-dialog>
  </div>
</template>
<script>
import { CreateMessage, GetMessageList, DeleteMessage } from "@/api/user";

export default {
  data() {
    return {
      form: {
        F_Name: this.$store.state.user.F_RealName,
        F_Email: "",
      },
      dialogVisible: false,
      MessageList: [],
      userId: this.$store.state.userId,
      BaseNull: false,
      pageSizs: 10,
      pageNum: 1,
      totalCount: 0
    };
  },
  async mounted() {
    this.GetMessageList();
  },
  methods: {
    onSizeChange(pageSizs) {
      this.pageSizs = pageSizs;
      this.GetMessageList();
    },
    onPageChange(pageNum) {
      this.pageNum = pageNum;
      this.GetMessageList();
    },
    CreateMessage() {
      CreateMessage({
        F_UserId: this.userId,
        ...this.form,
      }).then(() => {
        this.$message.success({ message: "创建成功", duration: 1200 });
        this.dialogVisible = false;
        this.GetMessageList();
      });
    },
    GetMessageList() {
      GetMessageList({
        F_UserId: this.userId,
        pageSizs: this.pageSizs,
        pageNum: this.pageNum,
      }).then((res) => {
        this.MessageList = res.data.Data;
        this.BaseNull = this.MessageList.length === 0;
        this.totalCount = res.data.totalCount;
      });
    },
    deletes(item) {
      DeleteMessage({
        F_CommentId: item.F_CommentId,
        F_UserId: this.userId,
      }).then(() => {
        this.GetMessageList();
      });
    },
    toItem(item) {
      this.$router.push({
        path: "/user/leavingMmessageDeatils",
        query: {
          F_CommentId: item.F_CommentId,
        },
      });
    },
  },
};
</script>
<style scoped lang="scss">
.li {
  padding: 20px;
  margin-top: 10px;
  .h4 {
    font-size: 18px;
  }
  .icons {
    margin-top: 30px;
    color: #666666;
  }
  .deletes {
    color: #e62e2e;
    cursor: pointer;
  }
  .item {
    margin-right: 58px;
  }
}
.pages {
  margin-top: 10px;
  padding: 15px 30px;
}
</style>